package pers.cz.service.impl;

import pers.cz.business.MessageBusiness;
import pers.cz.model.NotifyMessage;
import pers.cz.pub.BeanHelper;
import pers.cz.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: PostGirl-panent
 * @description: MessageServiceImpl
 * @author: Cheng Zhi
 * @create: 2021-10-07 22:23
 **/
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    public BeanHelper beanHelper;

    /**
     * 查询该用户下所有消息
     * @param userId
     * @return
     */
    @Override
    public List<NotifyMessage> queryAllNotifyMessage(Integer userId, Integer pageStart, Integer pageLimit) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);

        return business.queryAllNotifyMessage(userId, pageStart, pageLimit);
    }

    /**
     * 查询该用户下所有已读或者未读消息
     * @param userId
     * @param type
     * @return
     */
    @Override
    public List<NotifyMessage> queryAllNotifyMessageByType(Integer userId, String type, Integer pageStart, Integer pageLimit) {
        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.queryAllNotifyMessageByType(userId, type, pageStart, pageLimit);
    }

    /**
     * 根据消息类型查询该用户下所有消息
     * @param userId
     * @param messageType
     * @return
     */
    @Override
    public List<NotifyMessage> queryAllNotifyMessageByMessageType(Integer userId, String messageType, Integer pageStart, Integer pageLimit) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);

        return business.queryAllNotifyMessageByMessageType(userId, messageType, pageStart, pageLimit);
    }

    /**
     * 根据条件查询消息通知
     * @param userId
     * @param messageType
     * @param pageStart
     * @param pageLimit
     * @param type
     * @param startDate
     * @param endDate
     * @param theme
     * @return
     */
    @Override
    public List<NotifyMessage> queryNotifyMessagetByCondition(Integer userId, String messageType, Integer pageStart, Integer pageLimit, String type, Date startDate, Date endDate, String theme) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.queryNotifyMessagetByCondition(userId, messageType, pageStart, pageLimit, type, startDate, endDate, theme);
    }

    /**
     * 修改消息为已读或者未读
     * @param userId
     * @param id
     * @param type
     * @return
     */
    @Override
    public Integer updateNotifyMessageType(Integer userId, Integer id, String type) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.updateNotifyMessageType(userId, id, type);
    }

    /**
     * 修改消息类型
     * @param userId
     * @param id
     * @param messageType
     * @return
     */
    @Override
    public Integer updateNotifyMessageMessageType(Integer userId, Integer id, String messageType) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.updateNotifyMessageMessageType(userId, id, messageType);
    }

    @Override
    public Integer deleteMessageById(int id) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.deleteMessageById(id);
    }

    @Override
    public Integer quertNotifyMessageCount(int userId, String type) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.quertNotifyMessageCount(userId, type);
    }

    @Override
    public Integer updateNotifyMessageTypeAll(Integer userId, String type) {

        MessageBusiness business = new MessageBusiness();
        business.setMapper(beanHelper);
        return business.updateNotifyMessageMessageTypeAll(userId, type);
    }
}
